import django_filters
from .models import AdSpace, Advertisement, AdCampaign, AdPricing


class AdSpaceFilter(django_filters.FilterSet):
    position = django_filters.CharFilter(field_name='position', lookup_expr='icontains')
    is_active = django_filters.BooleanFilter()
    min_price = django_filters.NumberFilter(field_name='base_price', lookup_expr='gte')
    max_price = django_filters.NumberFilter(field_name='base_price', lookup_expr='lte')
    
    class Meta:
        model = AdSpace
        fields = ['position', 'is_active', 'min_price', 'max_price']


class AdvertisementFilter(django_filters.FilterSet):
    ad_space = django_filters.NumberFilter(field_name='ad_space__id')
    status = django_filters.ChoiceFilter(choices=Advertisement.STATUS_CHOICES)
    advertiser = django_filters.NumberFilter(field_name='advertiser__id')
    start_date = django_filters.DateFilter(field_name='start_date', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='end_date', lookup_expr='lte')
    
    class Meta:
        model = Advertisement
        fields = ['ad_space', 'status', 'advertiser', 'start_date', 'end_date']


class AdCampaignFilter(django_filters.FilterSet):
    status = django_filters.ChoiceFilter(choices=AdCampaign.STATUS_CHOICES)
    advertiser = django_filters.NumberFilter(field_name='advertiser__id')
    start_date = django_filters.DateFilter(field_name='start_date', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='end_date', lookup_expr='lte')
    
    class Meta:
        model = AdCampaign
        fields = ['status', 'advertiser', 'start_date', 'end_date']


class AdPricingFilter(django_filters.FilterSet):
    ad_space = django_filters.NumberFilter(field_name='ad_space__id')
    price_type = django_filters.ChoiceFilter(choices=AdPricing.PRICE_TYPES)
    is_active = django_filters.BooleanFilter()
    valid_from = django_filters.DateFilter(field_name='valid_from', lookup_expr='gte')
    valid_to = django_filters.DateFilter(field_name='valid_to', lookup_expr='lte')
    
    class Meta:
        model = AdPricing
        fields = ['ad_space', 'price_type', 'is_active', 'valid_from', 'valid_to']
